// 完整引入，体积比较大
// import "core-js";
// 按需引入
// import "core-js/es/promise";

import count from "./js/count";
import sum from "./js/sum";

// Preload/Prefetch 还可以使用第三方插件 @vue/preload-webpack-plugin
// Preload/Prefetch 存在一定兼容性问题，需要适当使用
import(/* webpackPreload: true */ './js/math.js');
import(/* webpackChunkName: "a", webpackPrefetch: true */ './js/a.js');

// import {mul} from "./js/math";
// 引入 Css 资源，Webpack才会对其打包
import "./css/index.css";
import "./less/index.less";
import "./sass/index.sass";
import "./sass/index.scss";
import "./styl/index.styl";
import "./css/iconfont.css"

document.getElementById('btn').onclick = function () {
    // webpackChunkName: "math"：这是webpack动态导入模块命名的方式，也叫webpack魔法命名
    // "math"将来就会作为[name]的值显示。
    import(/* webpackChunkName: "math" */ './js/math').then(({mul}) => {
        console.log(mul(3, 3));
    })
}

// console.log(mul(3,3));
console.log(count(2, 3));
console.log(sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

// 判断是否支持HMR功能
if (module.hot) {
    module.hot.accept("./js/count.js");
    module.hot.accept("./js/sum.js");
}


const promise = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(1)
    }, 1000)
})
promise.then(res => {
    console.log(res)
})

const a = [1,2,3,4];
a.includes(1);

if ("serviceWorker" in navigator) {
    window.addEventListener("load", () => {
        navigator.serviceWorker
            .register("/service-worker.js")
            .then((registration) => {
                console.log("SW registered: ", registration);
            })
            .catch((registrationError) => {
                console.log("SW registration failed: ", registrationError);
            });
    });
}